<?php

declare (strict_types=1);

namespace catchAdmin\monitor\command;

use Carbon\Carbon;
use catchAdmin\basics\model\Company;
use catchAdmin\basics\model\StorageFeeConfig;
use catchAdmin\basics\model\StorageFeeConfigInfo;
use catchAdmin\delivery\common\DeliveryUpsCommon;
use catchAdmin\order\model\OrderDeliver;
use catchAdmin\product\model\Product;
use catchAdmin\settlement\model\StorageFee;
use catchAdmin\settlement\model\StorageProductFee;
use catchAdmin\warehouse\model\WarehouseOrderProducts;
use catchAdmin\warehouse\model\WarehouseStock;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use catcher\Code;
use think\facade\Db;

class StockBackupCommand extends Command {
    protected $pid;

    protected function configure () {
        // 指令配置
        $this->setName('catch:StockBackup')
             ->setDescription('Stock Backup daily');
    }

    protected function execute (Input $input, Output $output) {
        try {
            $this->executeCommand();
        } catch (\Exception $e) {
            Log::error('StockBackup Error Line:' . $e->getLine());
            Log::error('StockBackup Error Code:' . $e->getCode());
            Log::error('StockBackup Error Message:' . $e->getMessage());
            throw new \Exception($e->getMessage());
        }
    }

    /**
     * 执行 command
     *
     * @time 2021年03月02日
     * @return void
     */
    protected function executeCommand () {

        Db::query("INSERT INTO warehouse_stock_logs (goods_code, entity_warehouse_id, virtual_warehouse_id , number, batch_no, goods_type, log_date, created_at)  SELECT goods_code, entity_warehouse_id, virtual_warehouse_id, number, batch_no, goods_type,date_format(now(), '%Y-%m-%d'), unix_timestamp(now()) FROM warehouse_stock");
    }

}
